<?php

	include 'util.php';

//check if user is logged in
	session_name('login');
	session_start();
	if($_SESSION['username'] == null)
	{
		//redirect back to home
		header("location: /home.php");
	}
	
	$userId = $_SESSION['userId'];
	//query for an active cart for user
	$dbConnection = getMySqlConnection();
	
	$query = "SELECT * FROM products WHERE product_id IN
				(SELECT product_id FROM cart WHERE order_id =
				(SELECT order_id FROM orders WHERE person_id = '$userId' AND active_ind = 1));";
	
	$result = $dbConnection->query($query);
	
// 	$cartArray = $result->fetch_assoc();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>
	<link rel="StyleSheet" type="text/css" href="css/tcaparrel.css">
	<link rel="StyleSheet" href="css/header.css" type="text/css">
	<script type="text/javascript" src="javascript/tcaparrel.js">
	</script>
</head>

<body>
<div class="contentWrapper">
	<div class="header">
		<?php 
		session_name('login');
		session_start();
		if(isset($_SESSION['username']))
		{
			include('loggedInUserHeader.php');
		}
		else
		{
			include ('loginformheader.php');
		}
		?>
	</div>
	
	<div class="menubarContentWrapper">
			<div class="menubar">
				<div class="menuItem" onclick="sweatshirts_click()"><label style="cursor: inherit">SweatShirts</label></div>
				<div class="menuItem" onclick="hats_click()"><label style="cursor: inherit">Hats</label></div>
				<div class="menuItem" onclick="tshirts_click()"><label style="cursor: inherit">T-Shirts</label></div>
				<div class="menuItem" onclick="pants_click()"><label style="cursor: inherit">Pants</label></div>
			</div>
	</div>
	
	<div class="body">
		<h1>Cart</h1>
		
		<table class="allUsers">
			<?php 
				//add remove button
				$totalPrice = 0;
				while ($cartItem = $result->fetch_assoc())
				{
					$name = $cartItem["product_name"];
					$category = $cartItem["category"];
					$price = $cartItem["price"];
					
					$totalPrice = $totalPrice + $price; 
					
					echo "<tr><td class='allUsers'>$name</td><td class='allUsers'>$category</td><td class='allUsers'>$$price</td></tr>";
				}
			?>	
			<tr>
				<td>
				Total:
				</td>
				<td> $
					<?php 
						//the total expenditures
						echo $totalPrice;
					?> 
				</td>
			</tr>
		</table>
	
		<input type="button" name="checkoutButton" value="Checkout" onclick="location.href='checkoutInfo.php';" /> 
	</div>
	
	<div class="footer"></div>
</div>
</body>

</html>